//
//  PzMeAgreementView.swift
//  Pz
//
//  Created by 蓝鳍互娱 on 2024/6/26.
//

import Foundation
import UIKit
import SnapKit
class PzMeAgreementView: UIView {
    var checkUserAgreementBlock: (() -> Void)?
    var checkPriveAgreementBlock: (() -> Void)?

    var agreementType:String?{
        didSet{
            if agreementType == "1"{//用户协议
                meHeadImgView.image = UIImage(named: "pzUserAgreementIcon")
                meHeadTitleLab.text = "用户协议"
                meHeadLineView.isHidden = false
            }else{
                meHeadImgView.image = UIImage(named: "pzPriveAgreementIcon")
                meHeadTitleLab.text = "隐私协议"
                meHeadLineView.isHidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        creatSubView()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var meHeadImgView: UIImageView = {
        let imageView = UIImageView()
        return imageView
    }()
    lazy var meHeadTitleLab: UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFont(ofSize: 28.fitScale(), weight: .bold)
        lab.textColor = UIColor(hex:0xD5C2EA)
        return lab
    }()
    lazy var meHeadGoImgView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "pzGoIcon")
        return imageView
    }()
    lazy var meHeadLineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex:0xFFFFFF,transparency: 0.3)
        return view
    }()
    lazy var meAgreementBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: #selector(meAgreement), for: .touchUpInside)
        return btn
    }()
    
    func creatSubView() {
        self.addSubview(meHeadImgView)
        self.addSubview(meHeadTitleLab)
        self.addSubview(meHeadGoImgView)
        self.addSubview(meHeadLineView)
        self.addSubview(meAgreementBtn)
        
        meHeadImgView.snp.makeConstraints { make in
            make.left.equalTo(61.fitScale())
            make.centerY.equalToSuperview()
            make.width.equalTo(34.fitScale())
            make.height.equalTo(34.fitScale())
        }
        meHeadTitleLab.snp.makeConstraints { make in
            make.left.equalTo(meHeadImgView.snp.right).offset(20.fitScale())
            make.centerY.equalTo(meHeadImgView)
            make.height.equalTo(40.fitScale())
        }
        meHeadGoImgView.snp.makeConstraints { make in
            make.right.equalTo(-69.fitScale())
            make.centerY.equalTo(meHeadImgView)
            make.width.equalTo(10.fitScale())
            make.height.equalTo(18.fitScale())
        }
        meHeadLineView.snp.makeConstraints { make in
            make.left.equalTo(64.fitScale())
            make.right.equalTo(-64.fitScale())
            make.bottom.equalTo(0.fitScale())
            make.height.equalTo(1)
        }
        meAgreementBtn.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    @objc func meAgreement(){
        if agreementType == "1"{
            self.checkUserAgreementBlock?()
        }else{
            self.checkPriveAgreementBlock?()
        }
    }
}
